//
//  HYFundsNavigationView.m
//  Chainup
//
//  Created by Sunline on 2018/6/13.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HYFundsNavigationView.h"
#import "JFKitPri.h"

@interface HYFundsNavigationView ()

@property(nonatomic,assign) CGFloat offset;

@end

@implementation HYFundsNavigationView

- (instancetype)initWithFrame:(CGRect)frame offset:(CGFloat)offset{
    self = [super initWithFrame:frame];
    _offset = offset;
    if (self) {
        [self setupUI:NO isRight:NO];
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguageNotify) name:KNotify_Language_Change object:nil];

    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame offset:(CGFloat)offset backBtn:(BOOL)isBack{
    self = [super initWithFrame:frame];
    _offset = offset;
    if (self) {
        [self setupUI:isBack isRight:NO];
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguageNotify) name:KNotify_Language_Change object:nil];

    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame offset:(CGFloat)offset backBtn:(BOOL)isBack rightBtn:(BOOL)isRight{
    self = [super initWithFrame:frame];
    _offset = offset;
    if (self) {
        [self setupUI:isBack isRight:isRight];
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguageNotify) name:KNotify_Language_Change object:nil];
    }
    return self;
}

-(void)dealloc{
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:KNotify_Language_Change object:nil];
}

#pragma mark - Notify
- (void)changeLanguageNotify{
    _titleLabel.text = NSLocalizedString(@"Funds", nil);
}

#pragma mark - UI
- (void)setupUI:(BOOL)isBack isRight:(BOOL)isRight{
    
    self.backgroundColor = [[UIColor awColorWithHexString:@"#3357A5"] colorWithAlphaComponent:0];
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20 + 15 +_offset, 200, 14)];
    _titleLabel.center = CGPointMake(self.center.x, _titleLabel.center.y);
    _titleLabel.text = NSLocalizedString(@"Funds", nil);
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_titleLabel];

    [self addSubview:self.titleButton];
    
    if (isBack) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _backButton.frame = CGRectMake(10, 20+7+_offset,30, 30);
        UIImage *backImage = [UIImage imageNamed:@"return"];
        [_backButton setImage:backImage forState:UIControlStateNormal];
        [self addSubview:_backButton];
    }
    
    if (isRight) {
        [self addSubview:self.rightButton];
    }
    
}


- (UIButton *)titleButton{
    if (!_titleButton) {
        UIImage *arrow = [UIImage imageNamed:@"stalls_arrow"];
        _titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _titleButton.frame = CGRectMake(0.f, 20 + _offset, 110, 40);
        _titleButton.center = CGPointMake(self.center.x, _titleButton.center.y);
        [_titleButton setImage:[UIImage image:arrow rotation:UIImageOrientationUp] forState:UIControlStateNormal];
        [_titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_titleButton setBackgroundColor:[UIColor clearColor]];
    }
    return  _titleButton;
}

- (UIButton *)rightButton{
    if (!_rightButton) {
        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightButton.frame = CGRectMake(self.frame.size.width - 35 - 10, 25 + _offset, 35, 35);
        [_rightButton setImage:[UIImage imageNamed:@"fullicon"] forState:UIControlStateNormal];
    }
    return _rightButton;
}




@end
